/**
 * @file xmlConfig.cpp
 * @brief XML配置文件源文件
 * @author zhangpeihao
 */
#include <zsystem/core/common/log.h>
#include <zsystem/core/xml/xmlGetOpt.h>

const Z_BOOL
zsystem::xmlGetOpt::parse(const Z_I32 argc, const char *const argv[])
{
	std::string str = "<cmdarg>";
	static const std::string::size_type npos = -1;
	for( Z_I32 i = 1; i < argc; ++i ) {
		std::string arg( argv[i] );
		std::string::size_type a, b, l;
		l = arg.length();
		a = arg.find( '-' );
		if( a != npos ) {
			b = arg.find( '=', a + 1 );
			if( b != npos ) {
				std::string node_name( arg.substr( a + 1, b - a - 1) ); 
				std::string node_value( arg.substr( b + 1, l - b - 1) );
				str += "<" + node_name + ">" + node_value + "</" + node_name +">";
			}
			else
			{
				std::string node_name( arg.substr( 1, l - 1) ); 
				str += "<" + node_name + "></" + node_name +">";
			}
		}
	}
	str += "</cmdarg>";
  _doc->Parse(str.c_str());
  if (_doc->Error())
  {
    return Z_FALSE;
  }
  return Z_TRUE;
}
